package pratice;

import java.util.Scanner;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class GetX2Value {
    X2Input X2Input = new X2Input();
    int SampleNumber = X2Input.SampleNumber();
    int i=2;
   // float X2value00;
   // float X2value01;
    float[] X2Value=new float[2];

    int  JudgeA(){
        Scanner sc= new Scanner(System.in);
        System.out.println("请输入显著性水平：");
        float a =sc.nextFloat();
        if(a==0.01){
            i=0;
        }else if(a==0.02) {
            i=2;
    }else if(a==0.05) {
            i=4;
        }
        else if(a==0.1) {
            i=6;
        }
        else if(a==0.2) {
            i=8;
        }
        else if(a==0.5) {
            i=10;
        }else{
            System.out.println("输入显著性水平有误：");
        }
        return i;
    }
    float[] readX2value() {
     // float[] X2Value=new float[2];
     //   System.out.println("样本容量为:" +SampleNumber);
        i= JudgeA();
        File Inputfile = new File("D:\\excel\\X2.xls");
        try {
            FileInputStream fileInputStream = new FileInputStream(Inputfile);
            Workbook workbook = Workbook.getWorkbook(fileInputStream);
            Sheet readfirst = workbook.getSheet(0);
            int rows = readfirst.getRows();
            int clomns = readfirst.getColumns();
            //       System.out.println("row:" + rows);
            //       System.out.println("clomns:" + clomns);
            Cell cell = readfirst.getCell(i, SampleNumber - 1);  //j在前 i 在后是根据excel下标来判断的
            String s = cell.getContents();
            //       System.out.println("cell:" + s);

            X2Value[0] = Float.parseFloat(s);

            Cell cell1 = readfirst.getCell(i+1, SampleNumber - 1);  //j在前 i 在后是根据excel下标来判断的
            String s1 = cell1.getContents();
            //       System.out.println("cell:" + s1);

            X2Value[1] = Float.parseFloat(s1);
            //       System.out.println("X2分布表对应较大值:" + X2value);

        } catch (
                Exception e) {
            e.printStackTrace();
        }

        return X2Value;

    }

}
